package com.ophiux.cs.application.appraise.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ophiux.cs.application.appraise.dto.GetCSDoctorAppraiseMasterRequest;
import com.ophiux.cs.application.appraise.dto.GetCSDoctorAppraiseMasterResponse;
import com.ophiux.cs.application.appraise.service.IGetCSDoctorAppraiseMasterAppService;
import com.ophiux.cs.application.core.Result;
import com.ophiux.cs.application.core.ResultEnum;
import com.ophiux.cs.domain.appraise.model.valueobj.DoctorAppraiseQueryObj;
import com.ophiux.cs.domain.appraise.model.valueobj.DoctorAppraiseValueObj;
import com.ophiux.cs.domain.appraise.repositories.IAppraiseRepository;
import com.ophiux.utils.common.ShiftUtils;
import com.ophiux.utils.exception.OphiuxRepositoryException;

import lombok.extern.slf4j.Slf4j;
@Service
@Slf4j
public class GetCSDoctorAppraiseMasterAppService implements IGetCSDoctorAppraiseMasterAppService {
	@Autowired
	IAppraiseRepository appraiseRepository;
	@Override
	public Result<List<GetCSDoctorAppraiseMasterResponse>> GetCSDoctorAppraiseMaster(GetCSDoctorAppraiseMasterRequest dto) {
		List<GetCSDoctorAppraiseMasterResponse> returnList=new ArrayList<GetCSDoctorAppraiseMasterResponse>();
		//验证参数是否允许为空
		if(!dto.isParamValid()) {
			return Result.fail(ResultEnum.requestParamFail.getCode(), ResultEnum.requestParamFail.getMsg());
		}
		try {
			DoctorAppraiseQueryObj dar=null;
			dar = (DoctorAppraiseQueryObj) ShiftUtils.objToNewObj(dto, DoctorAppraiseQueryObj.class);
			try {
				List<DoctorAppraiseValueObj> docList=appraiseRepository.getCSDoctorAppraiseMaster(dar);
				returnList = ShiftUtils.objToNewObjList(docList, GetCSDoctorAppraiseMasterResponse.class);
			} catch (OphiuxRepositoryException e) {
				e.printStackTrace();
				return Result.fail(ResultEnum.requestException.getCode(), e.getExceptionMessage());
			}
		} catch (Exception e) {
			log.info("【GetCSDoctorAppraiseMaster】接口异常：",e);
			e.printStackTrace();
			return Result.fail(ResultEnum.requestException.getCode(), "程序异常");
		}
		return Result.success(returnList, "查询医生咨询评价汇总成功");

	}
	
}
